Repository navigation
Handle quote-adjacent attributes in HTML sanitization - #77007
Conversation
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
| return replaceTagMarkup(s, (tagContent, match, malformed) => { | ||
| if (malformed) return `(${tagContent})`; | ||
| if (isHttpsAngleBracketAutolink(tagContent)) return match; | ||
|
|
||
| const tagNameMatch = tagContent.match(/^\/?\s*([A-Za-z][A-Za-z0-9]*)/); | ||
| if (tagNameMatch && allowedTags.includes(tagNameMatch[1].toLowerCase())) { | ||
| return `<${stripDangerousAttributes(tagContent)}>`; | ||
| } | ||
| return `(${tagContent})`; // Convert other tags to parentheses | ||
| return `(${tagContent})`; |
| if (!firstCharacter || !/[A-Za-z!]/.test(firstCharacter)) continue; | ||
|
|
||
| const boundary = findTagEnd(source, index); | ||
| if (boundary.end < 0) return written ? output + source.slice(written) : source; |
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Specification Reviewer completed successfully!
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. Design Decision Gate 🏗️Outcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills... |
|
✅ PR Code Quality Reviewer completed the code quality review.
|
There was a problem hiding this comment.
Reviewed head 02902f3 against safe-outputs specification v1.29.23, Section 9.2 Transformation T6 (unsafe XML tags MUST be converted to text), and security architecture NI-14/T-NI-009. REQUEST_CHANGES.
Blocking findings are already captured by the existing inline comments at sanitize_content_core.cjs lines 1271 and 1356: (1) when no unquoted tag terminator is found, replaceTagMarkup returns the remaining source unchanged, allowing raw/disallowed markup to bypass sanitization; (2) when a quoted > is treated as the fallback boundary, tagContent can include markup that is then parsed as part of an allowed tag, allowing disallowed tags hidden in quoted values to survive. Fix both paths and add regression tests. No specification update is appropriate: the PR behavior conflicts with existing mandatory sanitization requirements, and this review did not run tests per static-review policy.
Generated by PR Specification Reviewer for #77007 · copilot · gpt50 · ~2 AIC · ⌖ ~2 AIC · ⊞ 1.6K
Comment /review-specs to run again
|
@copilot address all review feedback |
There was a problem hiding this comment.
Static review completed. I found no additional distinct issues beyond the two existing review comments: the quote-aware scanner can preserve disallowed markup embedded in quoted values, and an unterminated tag boundary can return the remaining suffix unchanged. The specialist pass produced no parseable JSONL findings, so its output was discarded. No tests were run per the static-review instructions.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical parsing flaws allow tags and attributes to bypass sanitization, while malformed-quote recovery can cause quadratic processing time.
7 open issues
Avoid quadratic rescanning of malformed quoted tags · New Track quote state and recover malformed tag boundaries · New Recognize autolinks before tracking HTML quotes · New Escape embedded markup in neutralized tags · New End unquoted values only at whitespace or tag end · New Require a valid delimiter after tag names · New Recognize punctuated data attribute names · New
What changed in this PR
Updates the shared safe-output HTML sanitizer to address #77006: filtering quote-adjacent attributes while preserving safe quoted values.
Changes:
- Introduces quote-aware tag scanning for ordinary HTML and CDATA.
- Replaces regex attribute stripping with token scanning and adds malformed-quote handling.
- Adds exact-output regression cases for direct tag conversion and the full sanitization pipeline.
| File | Description |
|---|---|
actions/setup/js/sanitize_content_core.cjs |
Implements quote-aware tag boundaries and attribute filtering. |
actions/setup/js/sanitize_content_attributes.test.cjs |
Covers adjacent attributes, quoted > characters, malformed quotes, and CDATA. |
Review effort: Max (auto)
| return { end: index, malformed: false }; | ||
| } | ||
| } | ||
| return quote && firstQuotedGreaterThan >= 0 ? { end: firstQuotedGreaterThan, malformed: true } : { end: -1, malformed: false }; |
| function findTagEnd(source, start) { | ||
| let quote = ""; | ||
| let firstQuotedGreaterThan = -1; | ||
| for (let index = start + 1; index < source.length; index++) { | ||
| const character = source[index]; | ||
| if (quote) { | ||
| if (character === quote) { | ||
| quote = ""; | ||
| } else if (character === ">" && firstQuotedGreaterThan < 0) { | ||
| firstQuotedGreaterThan = index; | ||
| } | ||
| } else if (character === '"' || character === "'") { | ||
| quote = character; | ||
| } else if (character === ">") { | ||
| return { end: index, malformed: false }; | ||
| } | ||
| } | ||
| return quote && firstQuotedGreaterThan >= 0 ? { end: firstQuotedGreaterThan, malformed: true } : { end: -1, malformed: false }; | ||
| } |
| const firstCharacter = source[index + 1] === "/" ? source[index + 2] : source[index + 1]; | ||
| if (!firstCharacter || !/[A-Za-z!]/.test(firstCharacter)) continue; | ||
|
|
||
| const boundary = findTagEnd(source, index); |
| const end = boundary.end + 1; | ||
| const match = source.slice(index, end); | ||
| const tagContent = source.slice(index + 1, boundary.end); | ||
| output += source.slice(written, index) + transform(tagContent, match, boundary.malformed); |
| attributeEnd = closingQuote < 0 ? tagContent.length : closingQuote + 1; | ||
| } else { | ||
| attributeEnd = valueStart; | ||
| while (attributeEnd < tagContent.length && !/[\s>"'`<]/.test(tagContent[attributeEnd])) { |
| if (malformed) return `(${tagContent})`; | ||
| if (isHttpsAngleBracketAutolink(tagContent)) return match; | ||
|
|
||
| const tagNameMatch = tagContent.match(/^\/?\s*([A-Za-z][A-Za-z0-9]*)/); |
| } | ||
| } | ||
|
|
||
| if (/^(?:on\w+|style|title|data-[\w-]+)$/i.test(attributeName)) { |
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Addressed the sanitizer review findings in commits |
| const character = source[index]; | ||
| nextGreaterThan[index] = character === ">" ? index : nextGreaterThan[index + 1]; | ||
|
|
||
| normal[index] = character === ">" ? index + 1 : character === "=" ? expectValue[index + 1] : normal[index + 1]; |
|
@copilot run pr-finisher skill |
|
🎉 This pull request is included in a new release. Release: |


Filtered attributes could survive when adjacent to a quoted value, while
>inside quoted values could prematurely end tag scanning. Use quote-aware tag and attribute scanning so filtered attributes are removed consistently without matching text inside safe values.>characters and use the same scanner for CDATA tags.title,data-*,style, andon*attributes while preserving safe attributes.